package com.tjetc.view.studentview;

import com.github.pagehelper.PageInfo;
import com.tjetc.proxy.CilentProxy;
import com.zhiyun.domain.AdminNotice;
import com.zhiyun.domain.CourseComment;
import com.zhiyun.domain.Notice;
import com.zhiyun.service.AdminNoticeService;
import com.zhiyun.vo.Result;

import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Scanner;

public class StudentMainView {
    AdminNoticeService adminNoticeService= CilentProxy.getProxyInstance(AdminNoticeService.class);
     Scanner scanner=new Scanner(System.in);
    public void start() {
        while (true){
            System.out.println("~~~~~~~~~~~~~~~~~~学生主页面~~~~~~~~~~~~~~");
            System.out.println("1.我的课程");
            System.out.println("2.我的信息");
            System.out.println("3.公告");
            System.out.println("4.联系管理员");
            System.out.println("0.退出登录");
            int i = scanner.nextInt();
            switch (i){
                case 1:
                    new MyCourseView().start();
                    break;
                case 2:
                    new MyInfView().start();
                    break;
                case 3:
                    allNotice();
                    break;
                case 4:
                    new MyCallAdmin().start();
                    break;
                case 0:
                    return;
                default:
                    System.out.println("输入错误,请重新输入");

            }
        }
    }

    private void allNotice() {
        int a=1;
        boolean boo1=true;
        while (true){
            boolean boo=true;
            Result adminNoticeByPage = adminNoticeService.findAdminNoticeByPage(a);
            if (adminNoticeByPage.getCode()==200){
                PageInfo<AdminNotice> obj = (PageInfo<AdminNotice>) adminNoticeByPage.getObj();
                while (boo){
                    List<AdminNotice> list = obj.getList();
                    for (AdminNotice notice : list) {
                        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                        // 将Date转换为String
                        String dateString = sdf.format(notice.getCreateTime());
                        System.out.println("id:"+notice.getId()+"    内容:"+notice.getMessage()+"    时间:"+dateString);
                    }
                    System.out.println(obj.getPageNum()+"/"+obj.getPages());
                    System.out.println("请输入 上一页:0  下一页:1 退出:-1 ");
                    int i = scanner.nextInt();
                    switch (i){
                        case 0:
                            int prePage = obj.getPrePage();
                            System.out.println(prePage);
                            a=prePage;
                            boo=false;
                            break;
                        case 1:
                            int nextPage = obj.getNextPage();
                            System.out.println(nextPage);
                            a=nextPage;
                            boo=false;
                            break;
                        case -1:
                            return;
                    }
                }
            }

        }
    }
}
